﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using ST.Buz.Base;
using ST.Buz.Base.Entity;
using ST.Common.Util.Model;
using System.Collections.Generic;
using System.Linq;

namespace ST.Buz.Service
{
	public partial interface IServiceFinanceRecvDetail
	{
		List<IMS_FinanceRecvDetail> GetDetailList(int id, UserSession sessionCurrent);
	}

	public partial class ServiceFinanceRecvDetail
	{
		private readonly IServiceSysLog serviceSysLog;

		public ServiceFinanceRecvDetail(BuzContext ctx,
			IServiceSysLog _serviceSysLog,
			ILogger<ServiceFinanceRecvDetail> log)
		{
			serviceSysLog = _serviceSysLog;

			context = ctx;
			logger = log;
		}

		/// <summary>
		/// 获取详细信息
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		public List<IMS_FinanceRecvDetail> GetDetailList(int id, UserSession sessionCurrent)
		{
			var detailQuery = from d in context.FinanceRecvDetail
							  join due in context.FinanceRecvDue on d.DueID equals due.ID into duetmp
							  from dueall in duetmp.DefaultIfEmpty()
							  where d.RecvID == id
							  select new IMS_FinanceRecvDetail()
							  {
								  ID = d.ID,
								  DetailAddDate = d.DetailAddDate,
								  DueID = d.DueID,
								  DueSNo = d.DueSNo,
								  OrgID = d.OrgID,
								  Recved = d.Recved,
								  RecvID = d.RecvID,
								  //PaySNo = d.PaySNo,
								  DueRecv = dueall
							  };
			return detailQuery.AsNoTracking().ToList();
		}
	}
}